<?php

	session_start();
	require_once('../config.php');
	include_once("../database/DataBase.php");
	include_once("function.php");

	$cid = $_POST["cid"];
	$promo_code = $_POST["promo_code"];
	$promo_desc = $_POST["promo_desc"];
	$promo_type = $_POST["promo_type"];
	$start_date = $_POST["start_date"];
	$end_date = $_POST["end_date"];
	$limit = $_POST["limit"];
	$field_a = $_POST["field_a"];
	$field_b = $_POST["field_b"];
	$field_c = $_POST["field_c"];
	$create_by = $_SESSION["login_id"];
	$target = $_POST["target"];
	
	$database = New DataBase();
	$database->open_connection();
	
	$result = $database->addDiscount($cid, $promo_code, $promo_desc, $promo_type, $start_date, $end_date, $limit, $field_a, $field_b, $field_c, $target, $create_by);
	
	if($result){
		$database->LogAction($_SESSION["login_id"], "Add", "Add new areas from ".getIpAddress());
		$_SESSION["message"] = "New discount has been created ( Promo Code: ".$promo_code." )";
		header('Location: ../Message.php');
	}
	else{
		echo "fail";
	}
	
	$database->close_connection();
?>
